﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HanGu.Services.Interface;
using HanGu.Entity;
using HanGu.Common;
using System.Text;

namespace HanGu.CRM.Controllers
{
    public class AreaController : AdminBaseController
    {
        //private static readonly IArea serviceArea = ServiceFactory.GetService<IArea>();
        const string CITYFORMAT = "[\"{0}\", \"{1}\"]";
        public string GetCitys(string id)
        {
            StringBuilder strBuidler = new StringBuilder();
            var citys = serviceArea.GetCitys(id);
            strBuidler.Append(string.Format(CITYFORMAT, null, HelperCommon.SelectDefaultValue));           
            foreach (var item in citys)
            {
                strBuidler.Append(",");
                strBuidler.Append(string.Format(CITYFORMAT, item.AreaCode, item.AreaName));
                //if (citys.LastOrDefault() != item)
                //{ strBuidler.Append(","); }
            }
            return "["+strBuidler.ToString()+"]";
        }

        //
        // GET: /Area/

        public ActionResult Index()
        {
            return View(viewList, GetAreaList());
        }

        [HttpPost]
        public ActionResult Index(FormCollection collection)
        {

            SearchParma.Pagination.RowCount = null;
            return View(viewList, GetAreaList());
        }

        List<Area> GetAreaList()
        {
            List<Area> areaList = new List<Area>();// serviceArea.GetAll(base.SearchParma);
            //ViewData["RowCount"] = SearchParma.Pagination.RowCount;
            return areaList;
        }

        public ActionResult Create(int id)
        {
            Area area = new Area();
            return View(viewCreate, area);
        }

        //
        // POST: /Area/Create

        [HttpPost]
        [ValidateInput(false)]
        public string Create(FormCollection collection)
        {

            return "{" + ajaxStr + "}";
        }

        //
        // GET: /Area/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Area/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Area/Delete/5
        [HttpPost]
        public string Delete(int id, string guid)
        {
            return "{" + ajaxStr + "}";
        }
    }
}
